// pages/mystudent/index.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    students: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },
  onShow: function (options){   
    if (!app.globalData.userInfo) {
      wx.showModal({
        title: '提示',
        content: '你还没登录，请登录后再报名！',
        success(res) {
          if (res.confirm) {
            app.check();
          } else if (res.cancel) {
            console.log('用户点击取消')
          }
        }
      })
      return;
    }
    //获取学员
    wx.request({
      url: 'https://sng.tsletu.com/api/wxapp/user/getUserStudents',
      header: {
        'XX-Device-Type': 'wxapp',
        'XX-Token': app.globalData.token
      },
      success: res => {
        this.setData({
          students: res.data.data
        })        
      }
    })
    
    wx.hideLoading()
    
  },
  toAddStudent: function(res){
    wx.navigateTo({
      url: '/pages/addstudent/index',
    })
  },
  toEditStudent: function (res) {    
    wx.navigateTo({
      url: '/pages/editstudent/index?id='+ res.currentTarget.dataset.id,
    })
  },
  onPullDownRefresh: function () {
    this.onShow();
    wx.stopPullDownRefresh()
    wx.hideLoading();
  }
  
})